<template>
  <div class="common-page add-form">
    <SearchForm
      :search-list="searchList"
      :search-params="searchParams"
      @search="onSearch"
      @reset="onReset"
    />
    <el-form>
      <el-form-item>
        <div style="text-align: right">
          <el-button type="primary" @click="onAdd">新建</el-button>
        </div>
      </el-form-item>
    </el-form>
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"

        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >

        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="启用状态">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="(val) => onUpdateStatus(val, scope.row)" />
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="160px">
          <template slot-scope="scope">
            <el-button type="primary" @click="onEdit(scope.row)">编辑</el-button>
            <el-button type="danger" @click="onDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
    <AddUser ref="addUserFormRef" @get-page="onSearch" />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import AddUser from './add'
import { http } from '@/api'
export default {
  name: 'Index',
  components: {
    AddUser
  },
  mixins: [crud],
  data() {
    return {
      request: http.user,
      searchList: [
        {
          key: 'realname',
          name: 'input',
          label: '用户姓名'
        }
      ],
      searchParams: {
        realname: ''
      },
      columns: [
        { prop: 'realname', label: '用户姓名' },
        { prop: 'username', label: '用户账号' },
        { prop: 'phone', label: '联系方式' },
        { prop: 'departName', label: '单位单位' },
      ],
      tableData: [

      ]
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.accountTypeName = el.accountType == 0 ? '管理端用户' : '企业端用户'
        // el.statusType = this.options.find(item => item.value == el.status)?.type
        // el.atypeName = this.options2.find(item => item.value == el.atype)?.name
      })
    },
    onAdd() {
      this.$refs.addUserFormRef.open()
    },
    onEdit(item) {
      this.$refs.addUserFormRef.open(item)
    }
  }
}
</script>

<style scoped lang="scss">
</style>
